<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>watch</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        {{msg}}
        <!-- <button @click="msg=1">msg</button> -->
        <button @click="changeObj">msg</button>
    </div>
    <script>
        new Vue({
            el:"#app",
            data:{
                msg:"hello",
                obj:{
                    name:"1",
                    age:2
                }
            },
            methods:{
                changeObj(){
                    this.obj.name=2
                }
            },
            watch:{
                // msg(newValue,oldValue){
                //     console.log(newValue,oldValue);
                // }
                "obj.name":{
                    handler(newValue,oldValue){
                        console.log(newValue,oldValue);
                    }
                }
            }
        })
    </script>
</body>
</html>